Skip to content

[herd] More implicit transitive relations in the Cat interpreter#1719

Open
maranget wants to merge 4 commits intomasterfrom
more-transitive
Open

[herd] More implicit transitive relations in the Cat interpreter#1719
maranget wants to merge 4 commits intomasterfrom
more-transitive

Conversation

@maranget
Copy link
Copy Markdown
Member

@maranget maranget commented Feb 17, 2026

We notice that (...|r+|...)+ is (...|r|...)+ and thus also that irrefexivity of (...|r+|...)+ is equivalent to acyclicity of (...|r|...)

The process may be interesting because we also identify some of the recursive definitions that are equivalent to a transitive closure and represent them as (implicit) transitive closure, thereby saving some transitive closure operations.

However, to avoid the repetive evaluation of bound implicit transitive closures to explicit ones, we rely on an additionnal environment for implicitly transitive relations, introducing minor extra costs.

In the end, improvements are barely noticeable, but the interpreter should gain as regards performance robustness.

@maranget maranget force-pushed the more-transitive branch 2 times, most recently from 8702000 to ddb3be5 Compare February 17, 2026 23:50
begin
try
let es,saw_seq = as_plus_args false x es in
if saw_seq then Some (x,es) else None
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we have a warning that the rec flag is useless in that case?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather leave this to another PR.

…reter

We notice that `(...|r+|...)+` is `(...|r|...)+`
and thus also that irrefexivity of  `(...|r+|...)+`
is equivalent to acyclicity  of `(...|r|...)`.

The process may be interesting because we also
identify some of the recursive definitions that
are equivalent to a transitive closure and
represent them as (implicit) transitive closure,
thereby saving some transitive closure operations.

In practice, improvements are barely noticeable.
We take advantage of union commutativity
for performing this petty optimisation.
More precisely, bindings of the form `x = e`, where
the expression `e`potentially reduces to some transitive
closure (such as `e+`)  are handled specially,
by accepting an implicit transitive closure as a result.
@maranget maranget marked this pull request as ready for review February 19, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants